/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Chemin;

/**
 *
 * @author okaido
 */
public class LinkedListSpe {

    private int size;
    private Case first;
    private Case last;

    public LinkedListSpe() {
        this.size = 0;
        this.first = null;
        this.last = null;
    }

    public int getSize() {
        return size;
    }

    public Case getFirst() {
        return first;
    }

    public Case getLast() {
        return last;
    }

    public void push_front(Case mCase) {
        if (this.size == 0) {
            this.size = 1;
            this.first = mCase;
            this.last = mCase;
            mCase.setSucc(null);
            mCase.setPred(null);
        } else {
            this.size++;
            Case tempCase;
            tempCase = this.first;
            tempCase.setPred(mCase);
            mCase.setSucc(tempCase);
            mCase.setPred(null);
            this.first = mCase;
        }
    }

    public void push_back(Case mCase) {
        if (this.size == 0) {
            this.size = 1;
            this.first = mCase;
            this.last = mCase;
            mCase.setSucc(null);
            mCase.setPred(null);
        } else {
            this.size++;
            Case tempCase;
            tempCase = this.last;
            tempCase.setSucc(mCase);
            mCase.setPred(tempCase);
            mCase.setSucc(null);
            this.last = mCase;
        }
    }

    public void pop_front() {
        if (this.size == 0) {
            this.size = 0;
            this.first = null;
            this.last = null;
        } else {
            this.size--;
            this.first = this.first.getSucc();
            this.first.setPred(null);
        }
    }

    public void pop_back() {
        if (this.size == 0) {
            this.size = 0;
            this.first = null;
            this.last = null;
        } else {
            this.size--;
            this.last = this.last.getPred();
            this.last.setSucc(null);
        }
    }

    public void remove(Case mCase) {
        this.size--;
        if (mCase.getPred() == null) {
            this.first = this.first.getSucc();
            this.first.setPred(null);
        } else {
            if (mCase.getSucc() == null) {
                this.last = this.last.getPred();
                this.last.setSucc(null);
            } else {
                Case casePred = mCase.getPred();
                Case caseSucc = mCase.getSucc();
                casePred.setSucc(caseSucc);
                caseSucc.setPred(casePred);
            }
        }
    }

    public void insert( Case itCase, Case mCase) {
        if (itCase.getPred() == null) {
            this.push_front(mCase);
        } else {
            this.size++;
            Case casePred = itCase.getPred();
            casePred.setSucc(mCase);
            itCase.setPred(mCase);
            mCase.setSucc(itCase);
            mCase.setPred(casePred);

        }
    }

    public void removeAll(){
        this.first = null;
        this.last = null;
        this.size = 0;
        Case tempCase;
    }
}
